//
//  MainScene.m
//  Bridge
//
//  Created by vinh pham on 5/11/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "MainScene.h"
#import "BridgeAppDelegate.h"
#import "CCFileUtils.h"
#import "AboutScene.h"
#import "GameScene.h"
#import "OptionScene.h"

@implementation MainLayer

- (id) init {
    self = [super init];
    if (self != nil) {
        isTouchEnabled_ = TRUE;
    }
    return self;
}

- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //UITouch *touch = [touches anyObject];
    //startPoint = [touch locationInView:[touch view]];
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFadeTR transitionWithDuration:1 scene:[GameScene node]]];
}

@end

@implementation MainScene

- (id) init {
    self = [super init];
    if (self != nil) {
        CGSize winSize = [CCDirector sharedDirector].winSize;
        CCSprite *bg = [CCSprite spriteWithFile:[CCFileUtils fullPathFromRelativePath:@"bg_menu.png"]];
        [bg setPosition:ccp(winSize.width/2,winSize.height/2)];
		[self addChild:bg z:0];
        
        [self addChild:[MainLayer node]];
        
        CCMenuItemImage *btnSetting = [CCMenuItemImage itemFromNormalImage:[CCFileUtils fullPathFromRelativePath:@"option_icon.png"] selectedImage:[CCFileUtils fullPathFromRelativePath:@"option_icon.png"] target:self selector:@selector(chooseOption:)];
        [btnSetting setPosition:ccp(btnSetting.contentSize.width/2,btnSetting.contentSize.height/2)];
        
         CCMenuItemImage *btnAbout = [CCMenuItemImage itemFromNormalImage:[CCFileUtils fullPathFromRelativePath:@"about_icon.png"] selectedImage:[CCFileUtils fullPathFromRelativePath:@"about_icon.png"] target:self selector:@selector(chooseAbout:)];
        [btnAbout setPosition:ccp(btnSetting.contentSize.width*1.5,btnAbout.contentSize.height/2)];
        
        mainMenu = [CCMenu menuWithItems:btnSetting,btnAbout,nil];
		[mainMenu setPosition:ccp(0,0)];
		[self addChild:mainMenu];
    }
    return self;
}

- (void) chooseOption:(id)sender {
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFadeTR transitionWithDuration:1.0 scene:[OptionScene node]]];
}

- (void) chooseAbout:(id)sender {
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFadeTR transitionWithDuration:1.0 scene:[AboutScene node]]];
}

- (void) dealloc {
    [super dealloc];
}

@end
